package com.yuhong.reggie.mapper;

import com.yuhong.reggie.entity.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CategoryMapper {
    //根据类别id查询类别数据
    @Select("select *from category where id=#{id}")
    Category findByid(Long id);

    @Insert("insert into category values (null,#{type},#{name},#{sort},#{createTime},#{updateTime}," +
            "#{createUser},#{updateUser})")
    Integer save(Category category);

    @Select("select *from category where name=#{name}")
    CategoryMapper findByName(String name);

    @Select("select * from category order by sort asc")
    List<Category> findAll();

    //根据id删除
    @Delete("delete from category where id=#{id}")
    Integer delete(Long id);

    Integer update(Category category);
    //根据类名查询,排除自己
    @Select("select * from category where name=#{name} and id!=#{id}")
    Category findByName2(Category category);

    //根据类型查询类别的数据
    List<Category> findAllByType(@Param("type") Integer type);

}
